package com.hzhr.iot.user.convertor;

import com.hzhr.iot.user.convertor.custom.*;
import com.hzhr.iot.core.util.HzhrTypeUtil;
import com.hzhr.iot.core.util.HzhrJsonUtil;
import java.util.Map;
import com.hzhr.iot.user.model.role.RoleModel;
import com.hzhr.iot.user.model.role.RolePostModel;
import com.hzhr.iot.user.model.role.RolePutModel;
import com.hzhr.iot.user.entity.RoleEntity;
import com.hzhr.iot.user.entity.ext.RoleEntityExt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.hzhr.iot.user.model.role.RoleModel;
import com.hzhr.iot.user.model.role.RoleGetModel;
import com.hzhr.iot.user.model.role.RolePostModel;
import com.hzhr.iot.user.model.role.RolePutModel;
import com.hzhr.iot.user.queryModel.custom.RoleCustomQueryModel;

@Component
public class RoleConvertor {
    @Autowired
    ActionCustomConvertor actionCustomConvertor;
    @Autowired
    ActionInRoleCustomConvertor actionInRoleCustomConvertor;
    @Autowired
    CompanyCustomConvertor companyCustomConvertor;
    @Autowired
    DeptCustomConvertor deptCustomConvertor;
    @Autowired
    OptionsCustomConvertor optionsCustomConvertor;
    @Autowired
    ResourceCustomConvertor resourceCustomConvertor;
    @Autowired
    ResourceInActionCustomConvertor resourceInActionCustomConvertor;
    @Autowired
    UserCustomConvertor userCustomConvertor;
    @Autowired
    UserInRoleCustomConvertor userInRoleCustomConvertor;

    public RoleEntity roleModel2entity(RoleModel in) {
        //未转换字段: createUserId createTime updateUserId isValid updateTime state 
        if (in == null) return null;
        RoleEntity result = new RoleEntity();

        result.setId(HzhrTypeUtil.integer2integer(in.getId()));
        result.setName(HzhrTypeUtil.string2string(in.getName()));
        result.setCompanyId(HzhrTypeUtil.integer2integer(in.getCompanyId()));
        result.setRemarks(HzhrTypeUtil.string2string(in.getRemarks()));
        return result;
    }
    public RoleEntity roleModel2entity(RoleModel in, RoleEntity ori) {
        //未转换字段: createUserId createTime updateUserId isValid updateTime state 
        if (in == null) return null;
        RoleEntity result = ori;

        result.setId(HzhrTypeUtil.integer2integer(in.getId()));
        result.setName(HzhrTypeUtil.string2string(in.getName()));
        result.setCompanyId(HzhrTypeUtil.integer2integer(in.getCompanyId()));
        result.setRemarks(HzhrTypeUtil.string2string(in.getRemarks()));
        return result;
    }
    public List<RoleEntity> roleModelList2entityList(List<RoleModel> in) {
        if (in == null) return null;
        List<RoleEntity> result = new ArrayList<>();
        for (RoleModel item : in) {
            result.add(roleModel2entity(item));
        }
        return result;
    }
    public RoleModel entity2roleModel(RoleEntity in) {
        //未转换字段: 
        if (in == null) return null;
        RoleModel result = new RoleModel();

        result.setId(HzhrTypeUtil.integer2integer(in.getId()));
        result.setCompanyId(HzhrTypeUtil.integer2integer(in.getCompanyId()));
        result.setName(HzhrTypeUtil.string2string(in.getName()));
        result.setRemarks(HzhrTypeUtil.string2string(in.getRemarks()));
        return result;
    }
    public List<RoleModel> entityList2roleModelList(List<RoleEntity> in) {
        if (in == null) return null;
        List<RoleModel> result = new ArrayList<>();
        for (RoleEntity item : in) {
            result.add(entity2roleModel(item));
        }
        return result;
    }
    public RoleModel ext2roleModel(RoleEntityExt in) {
        //未转换字段: 
        if (in == null) return null;
        RoleModel result = new RoleModel();

        result.setId(HzhrTypeUtil.integer2integer(in.getId()));
        result.setCompanyId(HzhrTypeUtil.integer2integer(in.getCompanyId()));
        result.setName(HzhrTypeUtil.string2string(in.getName()));
        result.setRemarks(HzhrTypeUtil.string2string(in.getRemarks()));
        return result;
    }
    public List<RoleModel> extList2roleModelList(List<RoleEntityExt> in) {
        if (in == null) return null;
        List<RoleModel> result = new ArrayList<>();
        for (RoleEntityExt item : in) {
            result.add(ext2roleModel(item));
        }
        return result;
    }
    public RoleGetModel extList2roleGetModel(List<RoleEntityExt> extList, Integer total, Integer changeCount, Map<String, Object> query) {
        List<RoleModel> modelList = extList2roleModelList(extList);
        if (modelList == null) {
            RoleGetModel result = new RoleGetModel();
            result.setTotal(total);
            result.setChangeCount(changeCount);
            return result;
        }

         String _show = HzhrTypeUtil.object2string(query.get("_show"));
         Boolean _show_info = query.get("_show_info") != null ? Boolean.parseBoolean(query.get("_show_info").toString()) : false;

        if (!_show_info) {
            for (RoleModel model : modelList) {
                model.setName(null);
                model.setCompanyId(null);
                model.setRemarks(null);
            }
        }

        RoleGetModel result = new RoleGetModel();
        if ("one".equals(_show)) {
            if (modelList.size() > 0) {
                result.setModel(modelList.get(0));
            }
         }
        if ("list".equals(_show)) {
            result.setModelList(modelList);
        }
        result.setTotal(total);
        result.setChangeCount(changeCount);
        return result;
    }
    public RoleGetModel entity2roleGetModel(RoleEntity entity, Integer total, Integer changeCount, Map<String, Object> query) {
        List<RoleEntityExt> extList = new ArrayList<>();
        if (entity == null) return extList2roleGetModel(extList, total, changeCount, query);
        extList.add(HzhrJsonUtil.convertObjectType(entity, RoleEntityExt.class));
        return extList2roleGetModel(extList, total, changeCount, query);
     }
    public RoleEntity rolePostModel2entity(RolePostModel in) {
        //未转换字段: companyId createUserId createTime updateUserId isValid updateTime id state 
        if (in == null) return null;
        RoleEntity result = new RoleEntity();

        result.setName(HzhrTypeUtil.string2string(in.getName()));
        result.setRemarks(HzhrTypeUtil.string2string(in.getRemarks()));
        return result;
    }
    public RoleEntity rolePostModel2entity(RolePostModel in, RoleEntity ori) {
        //未转换字段: companyId createUserId createTime updateUserId isValid updateTime id state 
        if (in == null) return null;
        RoleEntity result = ori;

        result.setName(HzhrTypeUtil.string2string(in.getName()));
        result.setRemarks(HzhrTypeUtil.string2string(in.getRemarks()));
        return result;
    }
    public List<RoleEntity> rolePostModelList2entityList(List<RolePostModel> in) {
        if (in == null) return null;
        List<RoleEntity> result = new ArrayList<>();
        for (RolePostModel item : in) {
            result.add(rolePostModel2entity(item));
        }
        return result;
    }
    public RolePostModel entity2rolePostModel(RoleEntity in) {
        //未转换字段: 
        if (in == null) return null;
        RolePostModel result = new RolePostModel();

        result.setName(HzhrTypeUtil.string2string(in.getName()));
        result.setRemarks(HzhrTypeUtil.string2string(in.getRemarks()));
        return result;
    }
    public List<RolePostModel> entityList2rolePostModelList(List<RoleEntity> in) {
        if (in == null) return null;
        List<RolePostModel> result = new ArrayList<>();
        for (RoleEntity item : in) {
            result.add(entity2rolePostModel(item));
        }
        return result;
    }
    public RolePostModel ext2rolePostModel(RoleEntityExt in) {
        //未转换字段: 
        if (in == null) return null;
        RolePostModel result = new RolePostModel();

        result.setName(HzhrTypeUtil.string2string(in.getName()));
        result.setRemarks(HzhrTypeUtil.string2string(in.getRemarks()));
        return result;
    }
    public List<RolePostModel> extList2rolePostModelList(List<RoleEntityExt> in) {
        if (in == null) return null;
        List<RolePostModel> result = new ArrayList<>();
        for (RoleEntityExt item : in) {
            result.add(ext2rolePostModel(item));
        }
        return result;
    }
    public RoleEntity rolePutModel2entity(RolePutModel in) {
        //未转换字段: companyId createUserId createTime updateUserId isValid updateTime id state 
        if (in == null) return null;
        RoleEntity result = new RoleEntity();

        result.setName(HzhrTypeUtil.string2string(in.getName()));
        result.setRemarks(HzhrTypeUtil.string2string(in.getRemarks()));
        return result;
    }
    public RoleEntity rolePutModel2entity(RolePutModel in, RoleEntity ori) {
        //未转换字段: companyId createUserId createTime updateUserId isValid updateTime id state 
        if (in == null) return null;
        RoleEntity result = ori;

        result.setName(HzhrTypeUtil.string2string(in.getName()));
        result.setRemarks(HzhrTypeUtil.string2string(in.getRemarks()));
        return result;
    }
    public List<RoleEntity> rolePutModelList2entityList(List<RolePutModel> in) {
        if (in == null) return null;
        List<RoleEntity> result = new ArrayList<>();
        for (RolePutModel item : in) {
            result.add(rolePutModel2entity(item));
        }
        return result;
    }
    public RolePutModel entity2rolePutModel(RoleEntity in) {
        //未转换字段: 
        if (in == null) return null;
        RolePutModel result = new RolePutModel();

        result.setName(HzhrTypeUtil.string2string(in.getName()));
        result.setRemarks(HzhrTypeUtil.string2string(in.getRemarks()));
        return result;
    }
    public List<RolePutModel> entityList2rolePutModelList(List<RoleEntity> in) {
        if (in == null) return null;
        List<RolePutModel> result = new ArrayList<>();
        for (RoleEntity item : in) {
            result.add(entity2rolePutModel(item));
        }
        return result;
    }
    public RolePutModel ext2rolePutModel(RoleEntityExt in) {
        //未转换字段: 
        if (in == null) return null;
        RolePutModel result = new RolePutModel();

        result.setName(HzhrTypeUtil.string2string(in.getName()));
        result.setRemarks(HzhrTypeUtil.string2string(in.getRemarks()));
        return result;
    }
    public List<RolePutModel> extList2rolePutModelList(List<RoleEntityExt> in) {
        if (in == null) return null;
        List<RolePutModel> result = new ArrayList<>();
        for (RoleEntityExt item : in) {
            result.add(ext2rolePutModel(item));
        }
        return result;
    }
    public RoleCustomQueryModel roleService_query2queryModel(Map<String, Object> query) {
        RoleCustomQueryModel queryModel = new RoleCustomQueryModel();

        Integer _equal_id = HzhrTypeUtil.object2integer(query.get("_equal_id"));
        if (_equal_id != null) {
            queryModel.setEqual_id(_equal_id);
         }

        String _equal_name = HzhrTypeUtil.object2string(query.get("_equal_name"));
        if (_equal_name != null) {
            queryModel.setEqual_name(_equal_name);
         }

        Integer _equal_companyId = HzhrTypeUtil.object2integer(query.get("_equal_companyId"));
        if (_equal_companyId != null) {
            queryModel.setEqual_companyId(_equal_companyId);
         }

        Boolean _show_info = HzhrTypeUtil.object2boolean(query.get("_show_info"));
        if (_show_info != null && _show_info) {
            queryModel.setShow(true);
            queryModel.setShow(true);
            queryModel.setShow(true);
        }

        Integer page = HzhrTypeUtil.object2integer(query.get("_page"));
        Integer count = HzhrTypeUtil.object2integer(query.get("_count"));
        queryModel.setPage(page, count);

        return queryModel;
    }

}

